using Vin.Extension.Framework.Extension;
using Vin.Extension.Framework.Implement;
using Vin.Extension.Framework.Quartz.Dto.Entities;
using Vin.Extension.Framework.Quartz.Dto.List;
using Vin.Extension.Framework.Quartz.Entities;
using Vin.Extension.Framework.Quartz.Repository;
using Vin.Extension.Framework.Quartz.ServiceInterface;

namespace Vin.Extension.Framework.Quartz.Service;

public class SysJobRecordService : VinFrameworkBaseRecordServiceAsync<SysJobRecordDto, SysJobRecordListDto,
    SysJobRecordRepository, SysJobRecord>, ISysJobRecordService
{
    public override async Task<List<SysJobRecordDto>> ListAsync(SysJobRecordListDto dto)
    {
        var whereExpression = CreateExpressionable()
            .And(m => m.JobId == dto.JobId);

        var list = await _baseRepository.AsQueryable()
            .Where(whereExpression.ToExpression())
            .Select<SysJobRecordDto>(m => new SysJobRecordDto()
            {
                Id = m.Id,
                JobName = m.JobName,
                GroupId = m.GroupId,
                ExecuteTime = m.ExecuteTime,
                CostTime = m.CostTime,
                LoopCount = m.LoopCount,
                CurrentLoopCount = m.CurrentLoopCount,
                ClassName = m.ClassName,
                Status = m.Status,
                CreateTime = m.CreateTime
            })
            .ToObjectPageListAsync(dto);

        // return list.Adapt<List<SysJobRecordDto>>();
        return list;
    }
}